package zozopo.warehouse;


import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;


import zozopo.background.operator.operations.OperatorTB;
import zozopo.background.operator.operations.OperatorlimitedTB;
import zozopo.flow.comm.Flow;
import zozopo.flow.comm.FlowCode;

import zozopo.warehouse.operations.AftersaleserviceOS;
import zozopo.warehouse.operations.AftersaleserviceTB;


import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class AddAftersaleServiceAction extends ActionSupport implements Action,SessionAware{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private static final String limitedCode ="WAREHOUSE.AFTERSALESERVICE.ADD";
	
	//传入参数
	
	
	private int receiptlistid_aftersaleservice = 0;
	private String department_aftersaleservice = "";
	
	private String customerid_aftersaleservice = "";
	private String customerinfo_aftersaleservice = "";
	
	private String goodsinfo_aftersaleservice = "";
	
	private String receiveshipno_aftersaleservice = "";
	private String shipno_aftersaleservice = "";
	//private int shipprice_aftersaleservice = 0;
	private double receiveshipprice_aftersaleservice;
	
	private String problemdescription_aftersaleservice = "";
	
	private String remark_aftersaleservice = "";

	
	//private String receiptInfo = "";
	
	//传出参数
	private AftersaleserviceTB aftersaleservice;
	

	private String operationResult;

	
	private Map<Object, Object> session;
	public void setSession(Map arg0) {
		// TODO Auto-generated method stub
		session = arg0;
	}
	
	
	public String execute(){
		
		///权限处理
		OperatorTB operator = (OperatorTB)session.get("operatorInfo"); 
		//用户权限
		Map<String,OperatorlimitedTB> operatorlimitedMap = (Map<String,OperatorlimitedTB>)session.get("operatorlimitedMap");
		
		if(operator == null){
			addFieldError("errormessage", "用户未登陆或超时.请登陆后操作.");
			return NONE;
		}
		//DatabaseManager databaseManager = new BusiDatabaseManager();
		//Connection conn = databaseManager.getConnection();
		
		AftersaleserviceOS aftersaleserviceOS = new  AftersaleserviceOS();
		aftersaleservice = new AftersaleserviceTB();
		
		aftersaleservice.setCustomerid_aftersaleservice(customerid_aftersaleservice);
		aftersaleservice.setCustomerinfo_aftersaleservice(customerinfo_aftersaleservice);
		aftersaleservice.setDepartment_aftersaleservice(department_aftersaleservice);
		aftersaleservice.setProblemdescription_aftersaleservice(problemdescription_aftersaleservice);
		aftersaleservice.setGoodsinfo_aftersaleservice(goodsinfo_aftersaleservice);
		aftersaleservice.setReceiptlistid_aftersaleservice(receiptlistid_aftersaleservice);
		aftersaleservice.setRemark_aftersaleservice(remark_aftersaleservice);
		//aftersaleservice.setShipno_aftersaleservice(shipno_aftersaleservice);
		//aftersaleservice.setReceiveshipprice_aftersaleservice(receiveshipprice_aftersaleservice);
		aftersaleservice.setUseremail_aftersaleservice(operator.getEmail_operator());
		aftersaleservice.setUsername_aftersaleservice(operator.getName_operator());
		aftersaleservice.setReceiveshipno_aftersaleservice(receiveshipno_aftersaleservice);
	
		 
		if(!aftersaleserviceOS.insert(aftersaleservice)){
			operationResult = "插入失败!!!!!!!!!!!!!!!!!!!!!!!!";
		}else{
			aftersaleservice = aftersaleserviceOS.get(aftersaleserviceOS.getMaxIdByEmail(operator.getEmail_operator()));
			Flow flow = new Flow(aftersaleserviceOS.getConn());
			if(!flow.executeFlow(FlowCode.WAREHOUSE_AFTERSALESERVICE, aftersaleservice.getId_aftersaleservice(),null, operator, operatorlimitedMap,"")){
				//sqlError = true;
			}
		}
		
		aftersaleserviceOS.releaseConnection();
	
		
		return SUCCESS;//*/
		
	}
	
	public void validate() {
		//权限处理
		OperatorTB operator = (OperatorTB)session.get("operatorInfo"); 
	
		if(operator == null){
			addFieldError("errormessage",getText("operator.timeoutornotlogin"));
			return ; 
		} 
		
		//用户权限
		Map<String,OperatorlimitedTB> operatorlimitedMap = (Map<String,OperatorlimitedTB>)session.get("operatorlimitedMap");
		
		if(operatorlimitedMap.get(limitedCode) == null){
			addFieldError("errormessage","用户没有添加售后信息权限.");
			return;
		}
		
	}





	

	public String getOperationResult() {
		return operationResult;
	}


	public void setOperationResult(String operationResult) {
		this.operationResult = operationResult;
	}


	public int getReceiptlistid_aftersaleservice() {
		return receiptlistid_aftersaleservice;
	}


	public void setReceiptlistid_aftersaleservice(int receiptlistid_aftersaleservice) {
		this.receiptlistid_aftersaleservice = receiptlistid_aftersaleservice;
	}


	public String getDepartment_aftersaleservice() {
		return department_aftersaleservice;
	}


	public void setDepartment_aftersaleservice(String department_aftersaleservice) {
		this.department_aftersaleservice = department_aftersaleservice;
	}


	public String getCustomerid_aftersaleservice() {
		return customerid_aftersaleservice;
	}


	public void setCustomerid_aftersaleservice(String customerid_aftersaleservice) {
		this.customerid_aftersaleservice = customerid_aftersaleservice;
	}


	public String getCustomerinfo_aftersaleservice() {
		return customerinfo_aftersaleservice;
	}


	public void setCustomerinfo_aftersaleservice(
			String customerinfo_aftersaleservice) {
		this.customerinfo_aftersaleservice = customerinfo_aftersaleservice;
	}


	public String getGoodsinfo_aftersaleservice() {
		return goodsinfo_aftersaleservice;
	}


	public void setGoodsinfo_aftersaleservice(String goodsinfo_aftersaleservice) {
		this.goodsinfo_aftersaleservice = goodsinfo_aftersaleservice;
	}


	public String getShipno_aftersaleservice() {
		return shipno_aftersaleservice;
	}


	public void setShipno_aftersaleservice(String shipno_aftersaleservice) {
		this.shipno_aftersaleservice = shipno_aftersaleservice;
	}



	public String getRemark_aftersaleservice() {
		return remark_aftersaleservice;
	}


	public void setRemark_aftersaleservice(String remark_aftersaleservice) {
		this.remark_aftersaleservice = remark_aftersaleservice;
	}


	public AftersaleserviceTB getAftersaleservice() {
		return aftersaleservice;
	}


	public void setAftersaleservice(AftersaleserviceTB aftersaleservice) {
		this.aftersaleservice = aftersaleservice;
	}


	public String getReceiveshipno_aftersaleservice() {
		return receiveshipno_aftersaleservice;
	}


	public void setReceiveshipno_aftersaleservice(
			String receiveshipno_aftersaleservice) {
		this.receiveshipno_aftersaleservice = receiveshipno_aftersaleservice;
	}


	public double getReceiveshipprice_aftersaleservice() {
		return receiveshipprice_aftersaleservice;
	}


	public void setReceiveshipprice_aftersaleservice(
			double receiveshipprice_aftersaleservice) {
		this.receiveshipprice_aftersaleservice = receiveshipprice_aftersaleservice;
	}


	public String getProblemdescription_aftersaleservice() {
		return problemdescription_aftersaleservice;
	}


	public void setProblemdescription_aftersaleservice(
			String problemdescription_aftersaleservice) {
		this.problemdescription_aftersaleservice = problemdescription_aftersaleservice;
	}


	public static String getLimitedcode() {
		return limitedCode;
	}


	public static long getSerialversionuid() {
		return serialVersionUID;
	}




	


}
